<%@ page contentType="text/html;charset=UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ include file="../share/taglib.jsp"%>
<html>
<head>
<title>文件上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="/css/vip.css" type="text/css">
<link href="<%=basePath%>js/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=basePath%>js/jquery-1.3.1.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/uploadify/swfobject.js"></script>
<script type="text/javascript" src="<%=basePath%>js/uploadify/jquery.uploadify.v2.1.4.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    var fileName = $("#fileName");
    fileName.uploadify({
        'uploader'       : '<%=basePath%>js/uploadify/uploadify.swf',
        'script'         : '<%=basePath%>cms/uploadFile.do?method=saveTempFile${uploadFileForm.objType eq 'house' ? 'H' : 'B'}',
        'cancelImg'      : '<%=basePath%>js/uploadify/cancel.png',
        'scriptData'	 : {'objId':${uploadFileForm.objId},'objType':'${uploadFileForm.objType}'},
        'queueID'        : 'fileQueue',
        'auto'           : false,
        'multi'          : true,
        'removeCompleted': false,
        'queueSizeLimit' : 10,
        'simUploadLimit' : 999,
        'fileExt'        : '*.png;*.gif;*.jpg',
        'fileDesc'       : '图片文件(*.png;*.gif;*.jpg;)',
        'onAllComplete'  : function(event, data) {
            if (data.errors == 0) {
            	if(confirm('上传成功，是否跳转至图片列表页面？点击“取消”则继续上传')) {
            		window.location = '/cms/uploadFile.do?method=list${uploadFileForm.objType eq 'house' ? 'H' : 'B'}&objId=${uploadFileForm.objId}&objType=${uploadFileForm.objType}';
        		} else {
        			jQuery("#fileQueue").find('.uploadifyQueueItem').each(function() {
            			jQuery(this).remove();
            		});
        		}
            }
        },
        'onComplete'	 : function(event, ID, fileObj, response, data) {
            eval("var res = " + response + ";");
            if (!res.success) {
            	jQuery("#fileName" + ID).find('.percentage').text(" - Error : " + res.msg);
    			jQuery("#fileName" + ID).addClass('uploadifyError');
                return false;
            }
        }
    });
});
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<html:form action="/cms/uploadFile.do" method="post">
<input type="hidden" name="method" value="saveFile${uploadFileForm.objType eq 'house' ? 'H' : 'B'}" />
<input type="hidden" name="objType" />
<input type="hidden" name="objId" />
<table style="width:600px;" align="center">
   <tr align="left">
        <td colspan="2">
           <div id="fileQueue" class="uploadifyQueueDiv"></div>
        </td>
     </tr>
	<tr align="left">
		<td align="left" width="20%">
		   <input type="file" name="fileName" id="fileName" />
		</td>
		<td align="left">
           <button type="button" class="uploadifyButton" onclick="$('#fileName').uploadifyUpload();">上传并保存</button>
           <button type="button" class="uploadifyButton" onclick="$('#fileName').uploadifyClearQueue();">取消上传</button>
        </td>
	</tr>
</table>
</html:form>
</body>
</html>